﻿#include "VAOneXMLAdaptorAcousticsNCTSeptum.h"

#include "FITKAcousticsPhysics/FITKAcousticsNCTSeptum.h"

namespace IO
{
    bool VAOneXMLAdaptorAcousticsNCTSeptum::adaptR()
    {
        return readNCTSeptum();
    }

    bool VAOneXMLAdaptorAcousticsNCTSeptum::adaptW()
    {
        return writeNCTSeptum();
    }

    bool VAOneXMLAdaptorAcousticsNCTSeptum::readNCTSeptum()
    {
        if (!_node)// 判断Fluid节点是否存在
        {
            return false;
        }

        bool b = true;
        //转换类型
        Acoustics::FITKAcousticsNCTSeptum* layerData = dynamic_cast<Acoustics::FITKAcousticsNCTSeptum*>(_dataObj);

        if(!layerData)
        {
            return false;
        }

        double surfaceMass = readDoubleAttribute(_node, "mass_per_unit_area", &b);

        if(b)
        {
            layerData->setSurfaceMass(surfaceMass);
        }

        double thickness = readDoubleAttribute(_node, "thickness", &b);

        if(b)
        {
            layerData->setThickness(thickness);
        }

        return true;
    }

    bool VAOneXMLAdaptorAcousticsNCTSeptum::writeNCTSeptum()
    {
        if (!_node)// 判断节点是否存在
        {
            return false;
        }

        //转换类型
        Acoustics::FITKAcousticsNCTSeptum* layerData = dynamic_cast<Acoustics::FITKAcousticsNCTSeptum*>(_dataObj);

        if(!layerData)
        {
            return false;
        }

        //创建常规板节点
        rapidxml::xml_node<char>* node = createNodeElement(_node, "ResistiveTrimLayer");

        if(!node)
        {
            return false;
        }

        //写如属性值
        //写厚度
        writeAttribute(node, "thickness", layerData->getThickness());
        writeAttribute(node, "mass_per_unit_area", layerData->getMassPerUnitArea());
        return true;
    }

}
